package com.gem.controller;

import com.gem.domain.*;
import com.gem.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Set;
import java.util.TreeSet;

/**
 * @author Apolar_GuanYH-管阳红
 * Description: 联想输入JSON结果返回控制器
 * create 2019/10/28 11:46
 * Modified By:
 */
@Controller
@RequestMapping("/find")
public class JSONSearchController {

    //自动注入CompanyService
    private CompanyService companyService;

    @Autowired
    public void setCompanyService(CompanyService companyService) {
        this.companyService = companyService;
    }

    //自动注入UserService
    private UserService userService;

    @Autowired
    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    //自动注入TeacherService
    private TeacherService teacherService;

    @Autowired
    public void setTeacherService(TeacherService teacherService) {
        this.teacherService = teacherService;
    }

    //自动注入CCooperationResultService
    private CCooperationResultService cCooperationResultService;

    @Autowired
    public void setcCooperationResultService(CCooperationResultService cCooperationResultService) {
        this.cCooperationResultService = cCooperationResultService;
    }

    //自动注入CompanyContactService
    private CompanyContactService companyContactService;

    @Autowired
    public void setCompanyContactService(CompanyContactService companyContactService) {
        this.companyContactService = companyContactService;
    }

    //自动注入StudentService
    private StudentService studentService;
@Autowired
    public void setStudentService(StudentService studentService) {
        this.studentService = studentService;
    }

    //hrc人员集（所有hrc普通员工）
    @RequestMapping(value = "/hrcJson", method = RequestMethod.POST)
    @ResponseBody
    public Set<String> hrcJson() {
        Set<String> jsonSet = new TreeSet<>();
        List<User> mmembers = userService.findHrc();
        for (User mmember : mmembers) {
            jsonSet.add(mmember.getPersonname());
        }
        return jsonSet;
    }

    //企业名称集合
    @RequestMapping(value = "/companyNameJson", method = RequestMethod.POST)
    @ResponseBody
    public Set<String> companyNameJson() {
        Set<String> jsonSet = new TreeSet<>();
        List<Company> companys = companyService.findAllCompany();
        for (Company company : companys) {
            jsonSet.add(company.getCoName());
        }
        return jsonSet;
    }

    //授课人擅长内容集合
    @RequestMapping(value = "/tMajorJson", method = RequestMethod.POST)
    @ResponseBody
    public Set<String> tMajorJson() {
        Set<String> jsonSet = new TreeSet<>();
        List<Teacher> teacherList = teacherService.selectAllTeacher();
        for (Teacher teacher : teacherList) {
            jsonSet.add(teacher.getTMajor());
        }
        return jsonSet;
    }

    //就业人员集（就业/推荐老师）
    @RequestMapping(value = "/jobJson", method = RequestMethod.POST)
    @ResponseBody
    public Set<String> jobJson() {
        Set<String> jsonSet = new TreeSet<>();
        List<User> mmembers = userService.findJmembers();
        for (User mmember : mmembers) {
            jsonSet.add(mmember.getPersonname());
        }
        return jsonSet;
    }

    //市场人员集（渠道/咨询）
    @RequestMapping(value = "/marketJson", method = RequestMethod.POST)
    @ResponseBody
    public Set<String> marketJson() {
        Set<String> jsonSet = new TreeSet<>();
        List<User> mmembers = userService.findMmembers();
        for (User mmember : mmembers) {
            jsonSet.add(mmember.getPersonname());
        }
        return jsonSet;
    }

    //企培人员集（销售）
    @RequestMapping(value = "/salesJson", method = RequestMethod.POST)
    @ResponseBody
    public Set<String> salesJson() {
        Set<String> jsonSet = new TreeSet<>();
        List<User> mmembers = userService.findEmembers();
        for (User mmember : mmembers) {
            jsonSet.add(mmember.getPersonname());
        }
        return jsonSet;
    }

    //授课讲师集
    @RequestMapping(value = "/teacherJson", method = RequestMethod.POST)
    @ResponseBody
    public Set<String> teacherJson() {
        Set<String> jsonSet = new TreeSet<>();
        List<Teacher> teacherList = teacherService.selectAllTeacher();
        for (Teacher teacher : teacherList) {
            jsonSet.add(teacher.getTName());
        }
        return jsonSet;
    }

    //成果主题集
    @RequestMapping(value = "/topicJson", method = RequestMethod.POST)
    @ResponseBody
    public Set<String> topicJson() {
        Set<String> jsonSet = new TreeSet<>();
        List<CCooperationResult> cCooperationResultList = cCooperationResultService.selectAllCR();
        for (CCooperationResult cCooperationResult : cCooperationResultList) {
            jsonSet.add(cCooperationResult.getCrTopic());
        }
        return jsonSet;
    }

    //联系人姓名集
    @RequestMapping(value = "/contactNameJson", method = RequestMethod.POST)
    @ResponseBody
    public Set<String> contactNameJson() {
        Set<String> jsonSet = new TreeSet<>();
        List<CompanyContact> companyContactList = companyContactService.findAllCon();
        for (CompanyContact companyContact : companyContactList) {
            jsonSet.add(companyContact.getCoContactName());
        }
        return jsonSet;
    }

    //所有员工（除了老大）
    @RequestMapping(value = "/allUsersJson", method = RequestMethod.POST)
    @ResponseBody
    public Set<String> allUsersJson() {
        Set<String> jsonSet = new TreeSet<>();
        List<User> userList = userService.findAllUser();
        for (int i=userList.size()-1;i>=0;i--) {
            if(userList.get(i).getAuthority()!=3){
                userList.remove(i);
            }
        }
        for (User user : userList) {
            jsonSet.add(user.getPersonname());
        }
        return jsonSet;
    }

    //所有员工（含老大）
    @RequestMapping(value = "/allUsersNbossJson", method = RequestMethod.POST)
    @ResponseBody
    public Set<String> allUsersNbossJson() {
        Set<String> jsonSet = new TreeSet<>();
        List<User> userList = userService.findAllUser();
        for (User user : userList) {
            jsonSet.add(user.getPersonname());
        }
        return jsonSet;
    }

    //所有学生
    @RequestMapping(value = "/allStusJson", method = RequestMethod.POST)
    @ResponseBody
    public Set<String> allStusJson(Integer classId) {
        Set<String> jsonSet = new TreeSet<>();
        List<Student> studentList = studentService.selectAllStuByClassService(classId);
        for (Student student : studentList) {
            jsonSet.add(student.getSName());
        }
        return jsonSet;
    }
}
